package ace.module.weixin.core.autoconfig;

import ace.cmp.jetcache.anno.config.EnableAceMethodCache;
import ace.cmp.spring.data.jdbc.querydsl.core.QuerydslJdbcRepositoryExtendFactoryBean;
import ace.module.weixin.core.impl.WeixinCoreBootstrapScanner;
import ace.module.weixin.core.impl.dao.repository.RepositoryScanner;
import ace.module.weixin.core.impl.properties.WeixinCoreProperties;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.FilterType;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.stereotype.Repository;

/**
 * boostrap auto config.
 *
 * @author Caspar
 */
@EnableAspectJAutoProxy(exposeProxy = true)
@EnableAceMethodCache(basePackageClasses = {WeixinCoreBootstrapScanner.class})
@EnableConfigurationProperties({WeixinCoreProperties.class})
@EnableJdbcRepositories(basePackageClasses = {
    RepositoryScanner.class}, repositoryFactoryBeanClass = QuerydslJdbcRepositoryExtendFactoryBean.class)
@ComponentScan(basePackageClasses = WeixinCoreBootstrapScanner.class,
    excludeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Repository.class)
    })
@Configuration
public class WeixinCoreAutoConfig {

  @Bean
  public GroupedOpenApi weixinGroupedOpenApi() {
    return GroupedOpenApi.builder()
        .group("weixin")
        .displayName("微信服务")
        .packagesToScan(WeixinCoreBootstrapScanner.class.getPackageName())
        .build();
  }
}